package dao;

import java.math.BigInteger;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import entity.ProductEntity;

@Repository
public class ProductDaoImpl implements ProductDAO{
	
//	private static Logger log = Logger.getLogger(ProductDaoImpl.class);
	
	@Autowired
	private SessionFactory sessionFactory;
	
	public void addProduct(ProductEntity product) {
		this.sessionFactory.getCurrentSession().save(product);		
	}

	@SuppressWarnings("unchecked")
	public List<ProductEntity> getAllProduct() {
		return this.sessionFactory.getCurrentSession().createQuery("from ProductEntity").list();
	}

	public void deleteProduct(BigInteger productID) {
		ProductEntity product= (ProductEntity) sessionFactory.getCurrentSession().load(
				ProductEntity.class, productID);
		if (product != null)
			this.sessionFactory.getCurrentSession().delete(product);		
	}

}
